import { serverUrl, getRequest, postRequestForm } from '@/utils/request';

/**
 * @param 登录相关接口
 */

/**
 * @param {Object} 获取用户手机号
 */
const getPhoneNumber = (code, encryptedData, iv, deviceId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/getPhoneNumber', { code, encryptedData, iv, deviceId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * 登录接口
 * @param {Object} code - 唯一标识
 */
const login = (code) => {
  return new Promise((resolve, reject) => {
    getRequest('shiro/wechatMini/login', { code }, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {Object} 获取用户信息
 */
const getUserInfo = () => {
  return new Promise((resolve, reject) => {
    postRequestForm('shiro/wechatMini/getUserInfo', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * 补充用户信息
 * @param {Object} userInfo - 用户信息对象
 */
const supplementUserInfo = (userInfo) => {
  return new Promise((resolve, reject) => {
    postRequestForm('app/wechatMini/supplementUserInfo', userInfo, (res) => {
      resolve(res);
    });
  });
};

// const havePhone = () => {
//   return new Promise((resolve, reject) => {
//     getRequest('app/wechatMini/havePhone', {}, (res) => {
//       resolve(res);
//     });
//   });
// };

export { getPhoneNumber, login, getUserInfo, supplementUserInfo };
